/**
 * 北京市梧桐诗语文化传媒有限公司 版权所有
 * Copyright @2016-2020 All Rights Reserved
 */
package com.hnjme.cnec.common;

import org.springframework.util.StringUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author outta
 * @Since 1.0 2018/11/2
 */
public class DateUtils {

	public static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd";
	public static final String DEFAULT_DATETIME_FORMAT = "yyyy-MM-dd HH:mm:ss";

	public static Date parseDate(String date) throws ParseException {
		return parseDate(date,DEFAULT_DATE_FORMAT);
	}

	public static Date parseDate(String date,String format) throws ParseException {
		if(StringUtils.isEmpty(format)){
			format = DEFAULT_DATE_FORMAT;
		}
		return new SimpleDateFormat(format).parse(date);
	}

	public static Long secondsOfDate(Date date){
		return null == date? null: date.getTime() / 1000L;
	}


}
